home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 227_01 / graphics.h < prev    next >
Text File  |  1988-02-07  |  14KB  |  390 lines

  1. /*
  2.  * g r a p h i c s . h
  3.  * -------------------
  4.  * High-level header file. Contains all hardware-independant high-level
  5.  * defintions for the compatible graphics library. Does includes the
  6.  * generic low-level header-file "graf.h", if not forbidden (NOLLHINC set).
  7.  *
  8.  * update history
  9.  * --------------
  10.  * May, 28. 1987     Definitions for text-package added
  11.  * Jun, 17. 1987     Section "Configurable parameters" added in this file.
  12.  *                   This section allows it the user to configure some minor
  13.  *                   features of the library. First entry in this section is
  14.  *                   the preprocessor symbol COUTNRY. Allows text generation
  15.  *                   for different countrys.
  16.  * Jun, 20. 1987     Internal library implemtation mode added. This mode is
  17.  *                   enabled by #defineing LIB_MODE to 1 and is restriced
  18.  *                   to the graphics library only. User programs activating
  19.  *                   this mode may get totally confused!
  20.  * Aug, 30. 1987     Trigonemetric tables added.
  21.  *             Configuration tags USEENUM and LOADTRIG introduced.
  22.  *             Support for the write mode system added.
  23.  *
  24.  * Written by        Rainer Gerhards
  25.  *                   Petronellastr. 6
  26.  *                   D-5112 Baesweiler
  27.  *                   West Germany
  28.  *                   Phone (49) 2401 - 1601
  29.  */
  30.  
  31. /*
  32.  * Configurable parameters
  33.  * -----------------------
  34.  * The following parameters may be used to make minor configuration changes
  35.  * to the graphics library. They may be modified by the user and do not impact
  36.  * performance nor compatibility of the library. After modifications in this
  37.  * part, the whole library (including low-level drivers) must be recompiled!
  38.  *
  39.  * Note: The user should take extreme care when modifying this parameters,
  40.  *       even if this are only minor configuration parameters.
  41.  *       Modifications may result in parameter conflicts, which can't be
  42.  *       reported by all compilers.
  43.  */
  44.  
  45. /*
  46.  * The following defines are used to activate some language features,
  47.  * which are currently not common to all compilers.
  48.  */
  49. #define USEPROTT 1            /* function prototyping allowed    */
  50. #define USEVOID  1            /* type void allowed?        */
  51. #define    USEENUM     1            /* type enum allowed?        */
  52.  
  53. /*
  54.  * The following defines determine the optimization status of the library.
  55.  * If tag OPTTIME is #defined to 1, the execution time is optimized (resulting
  56.  * in larger memory allocation). If tag OPTSPACE is #defined to 1, the memory
  57.  * allocation is optimized (resulting in slower execution). If neither tag is
  58.  * #defined (or #defined to 0), the library uses a good compromise. Both tags
  59.  * can't be true at the same time.
  60.  * Note that this is only a minor request to the library coding. You should
  61.  * not expect to much from modifying these tags. However, in an (IBM-) PC
  62.  * environment I think it is the best guess to define OPTTIME.
  63.  */
  64. #define OPTTIME  1
  65. #define OPTSPACE 0
  66.  
  67. /*
  68.  * Select what to used: macros or function calls for the conversion and
  69.  * other frequently used functions. Macro usage can't be selected if
  70.  * OPTSPACE == true!
  71.  */
  72. #define USEMACS 1
  73.  
  74. /*
  75.  * The following tag controls the loading of the trigonemetric lookup tables.
  76.  * If it's defined to 0, they aren't loaded, otherwise they are loaded.
  77.  * Loading this tables is of use when working with function fellipsis, the
  78.  * turtle graphics system and the vector driven graphics functions (currently
  79.  * not implemented).
  80.  */
  81. #define LOADTRIG 1
  82.  
  83. /*
  84.  * The following define is used for country specific tasks, espicially
  85.  * for message processing. The country number is as defined in your DOS
  86.  * manual (international telephone country code).
  87.  *
  88.  * Currently supported countries are:
  89.  * Country                        Code
  90.  * United States of America          1
  91.  * Switzerland                      41
  92.  * Great Britain                    44
  93.  * Federal Republic of Germany      49
  94.  */
  95. #define COUNTRY 1
  96.  
  97. /*
  98.  * +-------------------------------------------------------------------------+
  99.  * |      E N D   O F   C O N F I G U R A B L E   P A R A M E T E R S        |
  100.  * +-------------------------------------------------------------------------+
  101.  *
  102.  * Please do not make any changes below this point!
  103.  */
  104. #ifndef __TURBOC__
  105.   #define defined(x) x
  106. #endif
  107.  
  108. #ifndef LIB_MODE
  109.   #define LIB_MODE 0
  110. #endif
  111.  
  112. /*
  113.  * Cross check the configurable parameters.
  114.  * If there are errors detected, and the compiler supports no text-output
  115.  * function, an syntax error is generated.
  116.  */
  117. #ifndef COUNTRY
  118.     "COUNTRY parameter must be defined!"
  119. #else
  120.   #if (COUNTRY != 1) && (COUNTRY != 41) && (COUNTRY != 44) && (COUNTRY != 49)
  121.       "Unsupported country specified!"
  122.   #endif
  123. #endif  /* end of country check */
  124.  
  125. /*
  126.  * cross-check optimization information
  127.  */
  128. #if OPTTIME && OPTSPACE
  129.     "Error: Can't specifiy both OPTTIME and OPTSPACE!"
  130. #endif
  131.  
  132. #if OPTSPACE && USEMACS
  133.     "Can't specifiy both OPTSPACE and USEMACS!"
  134. #endif
  135.  
  136. /*
  137.  * Convert some newer types to old types, if requested.
  138.  */
  139. #define    TRUE    -1
  140. #define    FALSE    0
  141.  
  142. #if    !USEVOID
  143. typedef int    void;
  144. #endif
  145.  
  146.  
  147. /* 
  148.  * WARNING:
  149.  * Turbo C V. 1.0 has an error in the constant folding algorithm.
  150.  * So do not use constant expressions, if this C compiler is active.
  151.  */
  152. #ifdef    __TURBOC__
  153.   #define    PI_D_180    0.017453293
  154. #else
  155.   #define    PI_D_180    PI / 180.0
  156. #endif
  157.  
  158. /*
  159.  * The following macro is used to declare data items as external usable
  160.  * (in library mode) or external defined (in user mode).
  161.  */
  162.  
  163. #if LIB_MODE == 2 /* master module? */
  164.   #define EXTERN
  165.   #define INITVAL(x) = (x)
  166. #else
  167.   #define EXTERN  extern
  168.   #define INITVAL(x)
  169. #endif
  170.  
  171. #if defined(DLC) || defined(__TURBOC__)
  172.   #define PI 3.14159265358979323846
  173.   #define iabs(x) abs(x)
  174. #endif
  175.  
  176. /*
  177.  *    support for the trigonometric functions
  178.  *    ---------------------------------------
  179.  *    These functions are generally very slow, and so the graphics
  180.  *    library uses a table of precomputed values, if not forbidden
  181.  *    (OPTSPACE == TRUE).
  182.  *    The trigonometric functions sin() and cos() are redifined by
  183.  *    intsin() and intcos(). This new functions perform the requested
  184.  *    action acording to the configuration switches. Their argument
  185.  *    is always in degrees.
  186.  */
  187. #if    LOADTRIG
  188.   #define    intsin(x)    sintab[x]
  189.   #define    intcos(x)    costab[x]
  190.   #if    LIB_MODE == 2
  191.     #include "trigtab.h"        /* load precomputed values    */
  192.   #else
  193.     extern float    sintab[361];
  194.     extern float    costab[361];
  195.   #endif
  196. #else
  197.   #define    intsin(x)    sin(torad(x))
  198.   #define    intcos(x)    cos(torad(x))
  199. #endif
  200.  
  201.  
  202. /*
  203.  * The following section contains macros to do some conversions, that are
  204.  * often needed in a graphics environment. This macros are also available
  205.  * as function calls and are only included if USEMACS is true. Your
  206.  * program should always think it uses the macro and thus should be free
  207.  * of side-effects!
  208.  */
  209. #if USEMACS
  210.                         /* arc conversion        */
  211.   #define todeg(x) ((x)/(PI_D_180))        /* radiant -> degree     */
  212.   #define torad(x) ((x)*(PI_D_180))        /* degree -> radiant     */
  213.                         /* coordinate conversion */
  214.   /*
  215.    * Note: when converting polar to cartesian coordinates, you have to
  216.    * correct the x radius, because the current resuloution doesn't correspond
  217.    * to the physical screen dimensions. If you wouldn't convert, you wouldn't
  218.    * get a real circle.
  219.    * The conversion can't be done by the macros below, because they don't
  220.    * know the current screen resolution (you may use your onw world
  221.    * coordinates). To aid you in the conversion task, an additional macro
  222.    * is supplied to correct the x radius. You have to supply the maximum
  223.    * x and y resolution and the radius to this macro. It then computes the
  224.    * actual x radius to use.
  225.    */
  226.   #define tocarxc(rad, arc) ((rad)*cos((double)(arc)))    /*polar->cartesian x*/
  227.   #define tocaryc(rad, arc) ((rad)*sin((double)(arc)))    /*polar->cartesian y*/
  228.   #define itocarxc(rad, arc) ((rad)*intcos((int)(arc)))    /*polar->cartesian x*/
  229.   #define itocaryc(rad, arc) ((rad)*intsin((int)(arc)))    /*polar->ca